var util = require('../../utils/util.js');
var api = require('../../config/api.js');
var Base64util = require("../../utils/base64.js");
var WxParse = require("../../lib/wxParse/wxParse.js")

var app = getApp();

Page({
  data: {
    tour: {},
    images: [],
    coverImage: "",
    imageNumber: 1,
    winWidth: 0,
    winHeight: 0,
    // tab切换  
    currentTab: 0,
    scrolly: true,
    section1Show: "block",
    section2Show: "none",
    section3Show: "none"
  },
  getData: function () {
    let that = this;
    wx.showLoading({
      title:'加载中',
      mask:true
    });
    util.request(api.TourDetail, { id: that.data.tour.id }).then(function (res) {
      wx.hideLoading();
      if (res.code === '200') {
        console.log(res.datas.tour)
        that.setData({
          tour: res.datas.tour,
          images: res.datas.images,
          coverImage: res.datas.images[0],
          imageNumber: res.datas.images.length
        });

        wx.setNavigationBarTitle({
          //页面标题为路由参数
          title: res.datas.tour.routeName
        })
        console.log("remark:", res.datas.tour.remark)
        WxParse.wxParse('remark', 'html', res.datas.tour.remark, that, 5);
        WxParse.wxParse('intr', 'html', res.datas.tour.introduction, that, 5);
      }
     
    });
  },

  onLoad: function (options) {
    var that = this;

    that.setData({
      tour: { id: options.id }//options为页面路由过程中传递的参数
    })
    // 页面初始化 options为页面跳转所带来的参数
    this.getData();
    /** 
      * 获取系统信息 
      */
    wx.getSystemInfo({

      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight
        });
      }

    });
    app.init(options, this);
  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    app.getShareInfo(this);
  },
  onHide: function () {
    // 页面隐藏

  },
  onUnload: function () {
    // 页面关闭

  },
  previewImage: function () {

    var that = this;
    if (that.data.images.length > 1) {


      wx.previewImage({
        current: 1, // 当前显示图片的http链接  
        urls: that.data.images// 需要预览的图片http链接列表  
      })
    }
  },
  /** 
     * 滑动切换tab 
     */
  bindChange: function (e) {
    var that = this;
    that.setData({ currentTab: e.detail.current });
    if (e.target.dataset.current == 0) {
      this.setData({
        section1Show: "block",
        section2Show: "none",
        section3Show: "none",
      })
    } else if (e.target.dataset.current == 1) {
      this.setData({
        section1Show: "none",
        section2Show: "block",
        section3Show: "none",
      })
    } else if (e.target.dataset.current == 2) {
      this.setData({
        section1Show: "none",
        section2Show: "none",
        section3Show: "block",
      })
    }
  },
  /** 
   * 点击tab切换 
   */
  swichNav: function (e) {

    var that = this;

    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
      if (e.target.dataset.current == 0) {
        this.setData({
          section1Show: "block",
          section2Show: "none",
          section3Show: "none",
        })
      } else if (e.target.dataset.current == 1) {
        this.setData({
          section1Show: "none",
          section2Show: "block",
          section3Show: "none",
        })
      } else if (e.target.dataset.current == 2) {
        this.setData({
          section1Show: "none",
          section2Show: "none",
          section3Show: "block",
        })
      }

    }
  },
  fnShowDetail: function (e) {
    var item = e.currentTarget.dataset.item;
    var url = "/pages/tourDayDetail/index?id=" + item.id;
    wx.navigateTo({
      url: url
    })
  },
  fnToOrder: function () {
    var url = "/pages/preOrder/tourOrder/tourorder?id=" + this.data.tour.id +
      "&type=tour";
    wx.navigateTo({
      url: url
    })
  },

  fnToIndex: function () {
    wx.switchTab({
      url: '/pages/index/index-new',
    })
  },
  //打电话
  makePhoneCall: function (e) {
    wx.makePhoneCall({
      phoneNumber: '4000282666',
    })
  },
  gotoHome: function () {
    wx.switchTab({
      url: '/pages/index/index',
    })
  },
  scroll: function (e) {
    console.log(e)
    this.setData({
      scrolly: false
    })
  }
})